package com.weixin.common;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @author lc
 * @email 389125111@qq.com
 * @create 2018-03-12 14:32
 */
@Setter
@Getter
@ToString
public class ResponseResult<T> {

    /**
     * 请求成功-有数据返回
     */
    private static final Integer result_success_data = 200;

    /**
     * 请求成功-无数据返回
     */
    private static final Integer result_success_no_data = 201;

    /**
     * 参数错误
     */
    private static final Integer param_error = 400;

    /**
     * 登录失效
     */
    private static final Integer login_timeout = 401;

    /**
     * 服务器错误
     */
    private static final Integer server_error = 500;


    private Integer code;
    private String msg;
    private T data;

    public static ResponseResult success(Object t) {
        ResponseResult result = new ResponseResult();
        result.setCode(result_success_data);
        result.setMsg("请求成功!");
        result.setData(t);
        return result;
    }

    public static ResponseResult success_data_null() {
        ResponseResult result = new ResponseResult();
        result.setCode(result_success_no_data);
        result.setMsg("请求成功,返回数据为空!");
        return result;
    }

    public static ResponseResult param_error() {
        ResponseResult result = new ResponseResult();
        result.setCode(param_error);
        result.setMsg("参数异常");
        return result;
    }

    public static ResponseResult login_timeout() {
        ResponseResult result = new ResponseResult();
        result.setCode(login_timeout);
        result.setMsg("登录失效");
        return result;
    }

    public static ResponseResult server_error() {
        ResponseResult result = new ResponseResult();
        result.setCode(server_error);
        result.setMsg("服务器错误");
        return result;
    }

    public static ResponseResult business_error(Integer code, String msg) {
        ResponseResult result = new ResponseResult();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

    /**
     * 请求未授权
     *
     * @return InvokeResult
     */
    public static ResponseResult unauthorizedError() {
        ResponseResult result = new ResponseResult();
        result.setCode(login_timeout);
        result.setMsg("无访问权限或token失效!");
        return result;
    }
}
